package org.example.leetCode;

/**
 * @author Administrator
 */
public class Exchange {

    public static void main(String[] args) {
        int[] nums = {1, 2, 3, 4};
        Exchange exchange = new Exchange();
        int[] exchange1 = exchange.exchange(nums);
        for (int i = 0; i < nums.length; i++) {
            System.out.println(nums[i]);
        }
    }


    public int[] exchange(int[] nums) {
        if (nums == null || nums.length < 2) {
            return nums;
        }
        int left = 0;
        int right = nums.length - 1;
        while (left < right) {
            while (left < right && nums[right] % 2 != 1) {
                right--;
            }
            while (left < right && nums[left] % 2 != 0) {
                left++;
            }
            int temp = nums[left];
            nums[left++] = nums[right];
            nums[right--] = temp;
        }
        return nums;
    }
}
